<style>
    /* .layui-form-item .layui-input-company {
        width: auto;
        padding-right: 10px;
        line-height: 38px;
    } */
    .layui-form-label {
        white-space: nowrap;
        position: relative;
        float: left;
        display: block;
        padding: 9px 15px;
        width: 80px;
        font-weight: 400;
        line-height: 20px;
        text-align: right;
    }

    .layui-input-block {
        width: 320px;
    }

    .item {
        display: flex;
        justify-content: center;
        padding: 5px;
    }


    .value {
        margin-left: 5vw;
    }
</style>
<form>
    <div class="layuimini-container layuimini-page-anim">
        <div class="layuimini-main">
            <div class="layui-form layuimini-form" lay-filter="setting">
                <fieldset class="layui-elem-field layui-field-title loukou-title" style="margin-top: 20px;">
                    <legend>系统设置</legend>
                </fieldset>

                <div class="layui-card-body">

                    <div class="layui-form-item item">

                        <label class="layui-form-label"> 校验时间:</label>

                        <div class="layui-input-block">
                            <input type="text" class="layui-input" id="SetTime" placeholder="yyyy-MM-dd HH:mm:ss">
                        </div>
                    </div>
                    <div class="layui-form-item item">

                        <label class="layui-form-label"> 硬件类型(无需重启):</label>

                        <div class="layui-input-block">
                            <select name="ComType" lay-filter="agreementfilter">
                                <option value="1" selected>GE200</option>
                                <option value="2">GT6758</option>
                            </select>
                            <input type="hidden" name="ID" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-form-item item">

                        <label class="layui-form-label"> 模组类型(重启生效):</label>

                        <div class="layui-input-block">
                            <select name="ATType">
                                <option value="1" selected>EC20 </option>
                                <option value="2">EC600M-CN</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item item">

                        <label class="layui-form-label"> 断点重传(重启生效):</label>

                        <div class="layui-input-block">
                            <input type="checkbox" name="IsRereported" lay-filter="IsRereported" title="开启|关闭"
                                lay-skin="switch">
                        </div>
                    </div>
                    <div class="layui-form-item item">

                        <label class="layui-form-label"> 看门狗(重启生效):</label>

                        <div class="layui-input-block">
                            <input type="checkbox" name="IsWatchdog" lay-filter="IsWatchdog" title="开启|关闭"
                                lay-skin="switch">
                        </div>
                    </div>
                    <div class="layui-form-item item">

                        <label class="layui-form-label"> 定时校时地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="TaskSetTimeUrl" autocomplete="off" placeholder="请输入"
                                lay-verify="required" class="layui-input layui-input-wrap">
                        </div>
                    </div>

                    <div class="layui-form-item item">
                        <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-submit
                            lay-filter="save">
                            保存</a>
                    </div>
                </div>
                <!-- <div class="layui-form-item">
                    <label class="layui-form-label ">设备名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" lay-verify="required" disabled class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">主机标识</label>
                    <div class="layui-input-block">
                        <input type="text" name="id" lay-verify="required" lay-reqtext="唯一识别编码不能为空"
                            placeholder="请设备唯一识别编码" value="" class="layui-input">
                    </div>
                </div>
               
                    <label class="layui-form-label">管理单位</label>
                    <div class="layui-input-block">
                        <input type="text" name="maintenancer" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">责&nbsp;&nbsp;任&nbsp;&nbsp;人</label>
                    <div class="layui-input-block">
                        <input type="text" name="manager" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">联系手机</label>
                    <div class="layui-input-block">
                        <input type="text" name="mobile" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">联系邮箱</label>
                    <div class="layui-input-block">
                        <input type="text" name="email" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="setting">保存</button>
                    </div>
                </div> -->
            </div>
        </div>
    </div>
</form>
<script src="../js/api.js" charset="utf-8"></script>
<script src="../js/ajaxRequest.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'laydate'], function () {
        var form = layui.form,
            $ = layui.jquery,
            layer = layui.layer;

        form.render();
        var laydate = layui.laydate;
        laydate.render({
            elem: '#SetTime',
            type: 'datetime',
            fullPanel: true, // 2.8+
            done: function (value, date, endDate) {
                var obj = { time: value }
                ChangeTime(obj)
            }

        });
        var loadingIndex = layer.load(3, {
            content: '加载中...', // 自定义加载文本
            shade: [0.4, '#fff'], // 遮罩透明度
            time: 5 * 1000,
        });
        GetSystemInfo().then(function (responseData) {
            layer.close(loadingIndex);
            data = responseData;
            if (data.code == 0) {
                //console.log('data', data)
                //console.log('form.val', form.val())
                // $("[name='ID']").val(item[key]);
                form.val('setting', {
                    'ComType': data.data.ComType == undefined ? "1" : data.data.ComType,
                    'ATType': data.data.ATType == undefined ? "1" : data.data.ATType,
                    'ID': data.data.ID
                });
                if (data.data.IsRereported == 1) {
                    $('input[name="IsRereported"]').prop('checked', true)
                } else {
                    $('input[name="IsRereported"]').prop('checked', false)
                }
                if (data.data.IsWatchdog == 1) {
                    $('input[name="IsWatchdog"]').prop('checked', true)
                } else {
                    $('input[name="IsWatchdog"]').prop('checked', false)
                }
                $("[name='TaskSetTimeUrl']").val(data.data.TaskSetTimeUrl)
                form.render('checkbox');
            }
        })


        form.on('submit(save)', function (data) {

            //console.log('data', data)
            var field = data.field
            field.ComType = parseInt(field.ComType)
            field.ATType = parseInt(field.ATType)
            field.ID = parseInt(field.ID)
            field.IsRereported = $("[name='IsRereported']").prop('checked') == true ? 1 : 0
            field.IsWatchdog = $("[name='IsWatchdog']").prop('checked') == true ? 1 : 0
            var obj = { SystemInfo: field }
            EditSystemInfo(obj).then(function (responseData1) {
                // console.log('responseData1',responseData1)
                if (responseData1.success) {

                }
            })
        })
        // checkbox 事件
        // form.on('switch(IsRereported)', function (data) {
        //     var elem = data.elem; // 获得 checkbox 原始 DOM 对象
        //     var checked = elem.checked; // 获得 checkbox 选中状态
        //     var value = elem.value; // 获得 checkbox 值
        //     var othis = data.othis; // 获得 checkbox 元素被替换后的 jQuery 对象
        //     console.log('value', value)
        //     console.log('elem', elem)
        //     layer.msg('checked 状态: ' + elem.checked);
        // });
    });
</script>